package com.yjh.server.service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yjh.pojo.entity.ReservationTime;
import com.yjh.server.mapper.ReservationTimeMapper;
import com.yjh.server.service.ReservationTimeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Service
public class ReservationTimeServiceImpl extends ServiceImpl<ReservationTimeMapper, ReservationTime> implements ReservationTimeService {
    @Autowired
    private ReservationTimeMapper reservationTimeMapper;
    @Override
    public List<ReservationTime> getInAvailableSlots(Integer courtId, LocalDate reserveDate) {
        // 校验参数（非空、日期合理性）
        if (courtId == null || reserveDate == null) {
            throw new IllegalArgumentException("球场ID和日期不能为空");
        }
        // 禁止预约过去的日期
        if (reserveDate.isBefore(LocalDate.now())) {
            throw new RuntimeException("无法预约过去的日期");
        }
        // 调用Mapper查询不可预约时段
        List<ReservationTime> reservationTimes = reservationTimeMapper.selectInAvailableSlots(courtId, reserveDate);
//        List<String> list = reservationTimes.stream().map(item -> item.getTimeSlot()).collect(Collectors.toList());
//        System.out.println(list);

        return reservationTimes;
    }
}
